
import VueRouter from 'vue-router'

const Login = () => import(/* webpackChunkName: "login_home_welcome" */ '../pages/Login')
const Home = () => import(/* webpackChunkName: "login_home_welcome" */ '../pages/Home')
const Welcome = () => import(/* webpackChunkName: "login_home_welcome" */ '../pages/main/Welcome')

const Orders = () => import(/* webpackChunkName: "Orders_Reports" */ '../pages/main/Orders.vue')
const Reports = () => import(/* webpackChunkName: "Orders_Reports" */ '../pages/main/Reports.vue')


const Categories = () => import(/* webpackChunkName: "Categories_Goods_Params_AddShoping" */ '../pages/main/Categories.vue')
const Goods = () => import(/* webpackChunkName: "Categories_Goods_Params_AddShoping" */ '../pages/main/Goods.vue')
const Params = () => import(/* webpackChunkName: "Categories_Goods_Params_AddShoping" */ '../pages/main/Params.vue')
const AddShoping = () => import(/* webpackChunkName: "Categories_Goods_Params_AddShoping" */ '../pages/main/AddShoping.vue')


const Rights = () => import(/* webpackChunkName: "Roles_Rights" */ '../pages/main/Rights.vue')
const Roles = () => import(/* webpackChunkName: "Roles_Rights" */ '../pages/main/Roles.vue')

const Users = () => import(/* webpackChunkName: "Users" */ '../pages/main/User.vue')


const router = new VueRouter({
  routes: [
    {
      path: "/",
      redirect: "/login",
    },
    {
      name: "login",
      path: "/login",
      component: Login,
    },
    {
      name: "home",
      path: "/home",
      component: Home,
      redirect:'/home/welcome',
      children:[{
        name:'Welcome',
        path:'welcome',
        component:Welcome
      },{
        name:'users',
        path:'users',
        component:Users
      },
    {
      name:'roles',
      path:'roles',
      component:Roles
    },
  {
    name:'rights',
    path:'rights',
    component:Rights
  },{
    name:'goods',
    path:'goods',
    component:Goods,
  },
    {
      name:'add',
      path:'goods/add',
      component:AddShoping 
    },
  {
    name:'params',
    path:'params',
    component:Params
  },{
    name:'categories',
    path:'categories',
    component:Categories
  },{
    name:'orders',
    path:'orders',
    component:Orders
  },{
    name:'reports',
    path:'reports',
    component:Reports
  }]
    },
  ],
})
router.beforeEach((to, from, next) => {
  if (to.fullPath !== "/login") {
    const token = sessionStorage.getItem("token")
    if (!token) {
      next("/login")
    }
  }
  next()
})

export default router
